#ifndef __MAINWIDGET_H__
#define __MAINWIDGET_H__

#include <QtGui>
#include <QDebug>


template<typename Type>
	class StackList:public QGroupBox
{
public:
	StackList(QWidget * paren=0,
		const QString& newBut="",
		const QString& delBut="");
	virtual ~StackList(); 
protected:
	QVector<Type> list;
	QGridLayout* glayout;
	QPushButton* newbut;
	QPushButton* delbut;
	virtual void update()=0;
};

template<typename Type>
StackList<Type>::StackList(QWidget * parent,
		const QString& newBut,
		const QString& delBut)
:QGroupBox(parent)
{
	glayout=new QGridLayout(this);
	newbut=new QPushButton(newBut,this);
	delbut=new QPushButton(delBut,this);
}

template<typename Type>
StackList<Type>::~StackList()
{
	for(int i=list.size()-1;i>=0;i--)
	{
		delete list[i];
	}
	delete glayout;
	delete newbut;
	delete delbut;
}



class SummWidget:public StackList<QLineEdit*>
{
Q_OBJECT
public:
	SummWidget(QWidget * parent=0,
		const QString& newBut=tr("New"),
		const QString& delBut=tr("Delete"));
	virtual ~SummWidget();
	QLabel* Lang;
	QLabel* Summary;
	QVector<QLineEdit*> lang;
	
	const QString commit();
public slots:
	void ADD(void);
	void DEL(void);
private:
	void update();
};


class SrcWidget:public StackList<QLineEdit*>
{
Q_OBJECT
public:
	SrcWidget(QWidget * parent=0,
		const QString& str="Source",
		const QString& newBut=tr("New"),
		const QString& delBut=tr("Delete"));
		
	const QString commit();
private:
	void update();
	QString Str;
public slots:
	void ADD();
	void DEL();
};

class DescWidget:public StackList<QTextEdit*>
{
Q_OBJECT
public:
	DescWidget(QWidget * parent=0,
		const QString& newBut=tr("New"),
		const QString& delBut=tr("Delete"));
	virtual ~DescWidget();
	QVector<QLineEdit*> lang;
	
	const QString commit();
public slots:
	void ADD(void);
	void DEL(void);
private:
	void update();
};

class HeadWidget:public QGroupBox
{
Q_OBJECT
public:
	HeadWidget(QWidget * parent = 0);
	
	const QString commit();
private:
	QGridLayout* glayout;
	QLabel* name;		QLineEdit* Name;
	QLabel* summary;	SummWidget* Summary;
	QLabel* version;	QLineEdit* Version;
	QLabel* release;	QLineEdit* Release;
	QLabel* license;	QLineEdit* License;
	QLabel* group;		QComboBox* Group;
	QLabel* source;		SrcWidget* Source;
	QLabel* patch;		SrcWidget* Patch;
	QLabel* requires;	QLineEdit* Requires;
	QLabel* brequires;	QLineEdit* BRequires;
	QLabel* buildroot;	QLineEdit* BuildRoot;
	QLabel* description;DescWidget* Description;
	void init_Group();
};


class ProcedureWidget:public QGroupBox
{
Q_OBJECT
public:
	ProcedureWidget(QWidget * parent = 0);
	
	const QString commit();
private:
	QVBoxLayout* vlayout0;
	QVBoxLayout* vlayout1;
	QVBoxLayout* vlayout2;
	QHBoxLayout* hlayout0;
	QHBoxLayout* hlayout1;
	QCheckBox* buildBox;
	QCheckBox* installBox;
	
//build scriplets
	QLabel* prep;
	QLabel* build;
	QLabel* install;
	QLabel* clean;
	QTextEdit* Prep;
	QTextEdit* Build;
	QTextEdit* Install;
	QTextEdit* Clean;
//install/erase scriplets
	QLabel* pre;
	QLabel* post;
	QLabel* preun;
	QLabel* postun;
	QTextEdit* Pre;
	QTextEdit* Post;
	QTextEdit* Preun;
	QTextEdit* Postun;
private slots:
	void update(int nothing=0);
};

class FileWidget:public QGroupBox
{
Q_OBJECT
public:
	FileWidget(QWidget * parent=0);
	
	const QString commit();
private:
	QGridLayout * glayout;
	QTextEdit * list;
};

class ChangeLogWidget:public QGroupBox
{
Q_OBJECT
public:
	ChangeLogWidget(QWidget * parent=0);
	
	const QString commit();
private:
	QGridLayout* glayout;
	QDateEdit* date;
	QLineEdit* info;
	QTextEdit* log;
};

class MainWidget:public QDockWidget
{
Q_OBJECT
public:
	MainWidget(const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = 0);
	
	const QString commit();
private:
	QScrollArea* scroll;
	QWidget* content;
	QVBoxLayout* vlayout;
	HeadWidget* head;
	ProcedureWidget* proc;
	FileWidget* file;
	ChangeLogWidget* changelog;
//	QVector<SubPackWidget*> subs;
};


#endif // __MAINWIDGET_H__
